package com.bw.module_service.ui

import androidx.activity.viewModels
import androidx.core.widget.doAfterTextChanged
import com.alibaba.android.arouter.facade.annotation.Route
import com.blankj.utilcode.util.ToastUtils
import com.bw.lib_common.arouter.Router
import com.bw.lib_common.base.BaseActivity
import com.bw.module_service.R
import com.bw.module_service.databinding.ActivityPostNoticeBinding
import com.bw.module_service.viewmodel.ServiceViewModel
import dagger.hilt.android.AndroidEntryPoint
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
data class AnnouncementForm(
    var title: String = "",
    var content: String = "",
    var type: String = "",
    var status: String = "待审核",
    var userId: String = "0",
    var publishTime: String = ""
)
@AndroidEntryPoint
@Route(path = Router.Ui.PostNoticeActivity)
class PostNoticeActivity : BaseActivity<ServiceViewModel, ActivityPostNoticeBinding>() {
    override val mLayoutResId: Int
        get() = R.layout.activity_post_notice

    private val mViewModel:ServiceViewModel by viewModels()

    private val formData = AnnouncementForm()
    override fun initView() {
    }


    override fun initData() {

        val map = mutableMapOf<String,Any>()

        mBinding.title.doAfterTextChanged { formData.title = it.toString() }
        mBinding.content.doAfterTextChanged { formData.content = it.toString() }
        mBinding.type.doAfterTextChanged { formData.type = it.toString() }

        formData.publishTime = SimpleDateFormat("yyyy-MM-dd", Locale.CHINA).format(Date())
        mBinding.addspceRg.setOnCheckedChangeListener { radioGroup, checkedId ->
            val statusText = when (checkedId) {
                R.id.rb_kx -> "待审核"
                R.id.rb_zy -> "已完成"
                R.id.rb_wh -> "已拒绝"
                R.id.rb_a1 -> "未阅读"
                else -> ""
            }
            map["status"] = statusText
        }
        map["userId"] = 0

        mBinding.btnPost.setOnClickListener {
            mViewModel.postAnnouncement(formData)
        }
    }

    override fun initListener() {
        mViewModel.postAnnouncementLiveData_.observe(this){
            ToastUtils.showLong("发布成功")
            finish()
        }
    }

}